/*
ID:fuxiang2
PROG: transform
LANG: C++
*/
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>

#define REP(i, n) for (int i=0;i<int(n);++i)
#define FOR(i, a, b) for (int i=int(a);i<int(b);++i)
#define DWN(i, b, a) for (int i=int(b-1);i>=int(a);--i)
#define REP_1(i, n) for (int i=1;i<=int(n);++i)
#define FOR_1(i, a, b) for (int i=int(a);i<=int(b);++i)
#define DWN_1(i, b, a) for (int i=int(b);i>=int(a);--i)
using namespace std;


ofstream fout ("transform.out");
ifstream fin ("transform.in");

const int N  = 12;
int mmap[N][N];
int re[N][N];
int temp[N][N];
void to90(int n)
{
	REP(i,n){
		REP(j,n){
			temp[j][n-i-1] = mmap[i][j];
		}
	}
	REP(i,n){
		REP(j,n){
			 mmap[i][j] = temp[i][j];
		}
	}
}

void fanse(int n)
{
	REP(i,n){
		REP(j,n){
			temp[i][n-j-1] = mmap[i][j];
		}
	}
	REP(i,n){
		REP(j,n){
			mmap[i][j] = temp[i][j];
		}
	}

}
bool isEqual(int n)
{
	REP(i,n){
		REP(j,n){
			if(re[i][j] != mmap[i][j])
				return false;
		}
	}
	return true;
}

int main() 
{

	int n;
	fin>>n;
	REP(i,n){
		REP(j,n){
			char ch;
			fin>>ch;
			mmap[i][j] =  (ch == '@' )?1 : 0;
		}
	}
	REP(i,n){
		REP(j,n){
			char ch;
			fin>>ch;
			re[i][j] =  (ch == '@' )?1 : 0;
		}
	}
	int result = -1;
	REP_1(i,3){
		to90(n);
		if (isEqual(n)){
			result = i;
			break ;
		}		
	}
	to90(n);
	if(result == -1 && isEqual(n))
		result = 6;

	if(result == -1 ){
		fanse(n);
		if(isEqual(n))
			result = 4;
	}

	if(result == -1 ){
		REP_1(i,3){
			to90(n);
			if (isEqual(n)){
				result = 5;
				break ;
			}		
		}
	}

	if(result== -1)
		result = 7;

	fout<< result <<endl;
	return 0;
}